package com.example.acer.demo.come;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.acer.demo.MainActivity;
import com.example.acer.demo.R;
import com.google.android.gms.common.api.GoogleApiClient;

/**
 * Created by acer on 2015/12/5.
 */
public class LoginActivity extends Activity implements View.OnClickListener {

    private EditText et_name, et_pwd;
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client;

    private TextView tv_login, tv_reg;

    private String name;
    private String password;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_login);

        initView();

    }



    private void initView() {
        et_name = (EditText) findViewById(R.id.et_name);
        et_pwd = (EditText) findViewById(R.id.et_pwd);

        tv_login = (TextView) findViewById(R.id.tv_login);
        tv_reg = (TextView) findViewById(R.id.tv_reg);


        tv_login.setOnClickListener(this);
        tv_reg.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        name = et_name.getEditableText().toString().trim();
        password = et_pwd.getEditableText().toString().trim();
        switch (v.getId()) {
            case R.id.tv_login:
                if (TextUtils.equals(name, null)) {
                    Toast.makeText(this, "用户名为空", Toast.LENGTH_SHORT).show();

                } else if (TextUtils.equals(password, null)) {
                    Toast.makeText(this, "密码为空", Toast.LENGTH_SHORT).show();

                } else {

                    if (TextUtils.equals(name, "123") && TextUtils.equals(password, "123")) {
                        Intent i = new Intent(this, MainActivity.class);
                        startActivity(i);
                        overridePendingTransition(R.anim.abc_fade_in,R.anim.abc_fade_out);
                    } else {
                        Toast.makeText(this, "输入有误", Toast.LENGTH_SHORT).show();
                    }
                }
                break;
            case R.id.tv_reg:

                Toast.makeText(this, "注册", Toast.LENGTH_SHORT).show();

                break;

        }
    }


}
